import os
import sys
import argparse
_cur = os.path.dirname(__file__)
sys.path.extend([_cur, os.path.dirname(_cur)])

from transfer.server import server
from transfer.service import RegisterFunction
from server.Services import Services
from server.initdata import db_init

# 注册独立函数
RegisterFunction.do_register(server)
# 注册Services类
server.register_instance(Services())

def main():
    parser = argparse.ArgumentParser(description='服务器管理工具')
    subparsers = parser.add_subparsers(dest='command', help='可用命令')

    subparsers.add_parser('start', help='启动服务器')
    subparsers.add_parser('dbinit', help='数据库初始化')
    
    args = parser.parse_args()
    
    if not args.command:
        server.start()
    elif args.command == 'start':
        server.start()
    elif args.command == 'dbinit':
        db_init()

if __name__ == '__main__':
    main()